﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace AcademiaInteligenteData.DAL
{
    class DaoPlaylist : DaoConnection
    {
        public void InserirPlaylist(Playlist playlist)
        {
            string insertPlaylist = "ai_sp_inserirPlaylist";
            List<SqlParameter> parametros = new List<SqlParameter>();

            parametros.Add(new SqlParameter("@id", playlist.id));
            parametros[0].Direction = System.Data.ParameterDirection.InputOutput;                      
            parametros.Add(new SqlParameter("@descricao", playlist.descricao));            
            
            Executar(insertPlaylist, true, parametros);
            playlist.id = Convert.ToInt32(parametros[0].Value);
        }
        public void AlterarPlaylist(Playlist playlist)
        {
            string alterarPlaylist = "ai_sp_alterarPlaylist";
            List<SqlParameter> parametros = new List<SqlParameter>();

            parametros.Add(new SqlParameter("@id", playlist.id));            
            parametros.Add(new SqlParameter("@descricao", playlist.descricao));
                       
            Executar(alterarPlaylist, true, parametros);
        }
        public void ExcluirPlaylist(int id)
        {
            string excluirPlaylist = "ai_sp_excluirPlaylist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", id));
            Executar(excluirPlaylist, true, parametros);
        }
        public Playlist SelecionarPlaylistPorID(int id)
        {
            string selecionaPlaylist = "ai_sp_selecionarPlaylistPorID";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", id));
            DataSet reader = Selecionar(selecionaPlaylist, true, parametros);
            int i = 0;
            Playlist playlist = new Playlist();                       
            playlist.descricao= Convert.ToString(reader.Tables[0].Rows[i]["descricao"]);
            playlist.id = id;
            return playlist;
        }

        public List<Playlist> ListarPlaylist()
        {
            string listaPlaylist = "ai_sp_listarPlaylist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            DataSet reader = Selecionar(listaPlaylist, true, parametros);
            List<Playlist> playlists = new List<Playlist>();
            for (int i = 0; i < reader.Tables[0].Rows.Count; i++)
            {
                Playlist playlist = new Playlist();                               
                playlist.descricao = Convert.ToString(reader.Tables[0].Rows[i]["descricao"]);                
                playlist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id"]);
                playlists.Add(playlist);
            }
            return playlists;
        }

        internal List<Playlist> SelecionarPlaylistPorAmbiente(int idAmbiente)
        {
            string selecionaPlaylist = "ai_sp_selecionarPlaylistPorAmbiente";            
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id_ambiente", idAmbiente));            
            DataSet reader = Selecionar(selecionaPlaylist, true, parametros);
            List<Playlist> playlists = new List<Playlist>();
            for (int i = 0; i < reader.Tables[0].Rows.Count; i++)
            {
                Playlist playlist = new Playlist();               
                playlist.descricao = Convert.ToString(reader.Tables[0].Rows[i]["descricao"]);                
                playlist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id"]);                
            }
            return playlists;
        }
    }
}
